/*
 * Copyright (c) 2025 彭友聪
 * nativePC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2. 
 * You may obtain a copy of Mulan PSL v2 at:
            http://license.coscl.org.cn/MulanPSL2 
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
 * See the Mulan PSL v2 for more details.  
 * 
 * Author: 彭友聪 
 * email：2923616405@qq.com 
 * date: 2025/10/8 08:46
 * file: ${FILE_NAME}
 * product: DevEco Studio
 * LICENSE: MulanPSL-2.0
 * */
//
// Created on 2025/10/8.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef NATIVEPC_NATIVEENTRY_H
#define NATIVEPC_NATIVEENTRY_H
#include "napi/native_api.h"
#include <ArkUIBaseNode.h>
#include <arkui/native_node.h>
#include <arkui/native_type.h>
#include <js_native_api_types.h>

namespace NativeModule
{
    napi_value CreateNativeRoot(napi_env env, napi_callback_info info);
    napi_value DestroyNativeRoot(napi_env env, napi_callback_info info);
    void showUITextCallback(std::string tip, std::string content);
    ArkUI_ContextHandle getGlobalUIContext();
} // namespace NativeModule

class NativeEntry
{
    private:
        std::shared_ptr<NativeModule::ArkUIBaseNode> root_;
        ArkUI_NodeContentHandle handle_;

    public:
        static NativeEntry *GetInstance()
        {
            static NativeEntry nativeEntry;
            return &nativeEntry;
        }

        void SetContentHandle(ArkUI_NodeContentHandle handle) { handle_ = handle; }

        void SetRootNode(const std::shared_ptr<NativeModule::ArkUIBaseNode> &root)
        {
            root_ = root;
            // 添加 Native 组件到 NodeContent 上用于挂载显示
            OH_ArkUI_NodeContent_AddNode(handle_, root_->GetHandle());
        }

        void DisposeRootNode()
        {
            OH_ArkUI_NodeContent_RemoveNode(handle_, root_->GetHandle());
            root_.reset();
        }
};

#endif //NATIVEPC_NATIVEENTRY_H
